/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.zcm.modules.nbg.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.zcm.common.config.Global;
import com.zcm.common.persistence.Page;
import com.zcm.common.web.BaseController;
import com.zcm.common.utils.StringUtils;
import com.zcm.modules.nbg.entity.NbgLtyaogu;
import com.zcm.modules.nbg.service.NbgLtyaoguService;

/**
 * 妖股Controller
 * @author www
 * @version 2018-10-02
 */
@Controller
@RequestMapping(value = "${adminPath}/nbg/nbgLtyaogu")
public class NbgLtyaoguController extends BaseController {

	@Autowired
	private NbgLtyaoguService nbgLtyaoguService;
	
	@ModelAttribute
	public NbgLtyaogu get(@RequestParam(required=false) String id) {
		NbgLtyaogu entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = nbgLtyaoguService.get(id);
		}
		if (entity == null){
			entity = new NbgLtyaogu();
		}
		return entity;
	}
	
	@RequiresPermissions("nbg:nbgLtyaogu:view")
	@RequestMapping(value = {"list", ""})
	public String list(NbgLtyaogu nbgLtyaogu, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<NbgLtyaogu> page = nbgLtyaoguService.findPage(new Page<NbgLtyaogu>(request, response), nbgLtyaogu); 
		model.addAttribute("page", page);
		return "modules/nbg/nbgLtyaoguList";
	}

	@RequiresPermissions("nbg:nbgLtyaogu:view")
	@RequestMapping(value = "form")
	public String form(NbgLtyaogu nbgLtyaogu, Model model) {
		model.addAttribute("nbgLtyaogu", nbgLtyaogu);
		return "modules/nbg/nbgLtyaoguForm";
	}

	@RequiresPermissions("nbg:nbgLtyaogu:edit")
	@RequestMapping(value = "save")
	public String save(NbgLtyaogu nbgLtyaogu, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, nbgLtyaogu)){
			return form(nbgLtyaogu, model);
		}
		nbgLtyaoguService.save(nbgLtyaogu);
		addMessage(redirectAttributes, "保存妖股成功");
		return "redirect:"+Global.getAdminPath()+"/nbg/nbgLtyaogu/?repage";
	}
	
	@RequiresPermissions("nbg:nbgLtyaogu:edit")
	@RequestMapping(value = "delete")
	public String delete(NbgLtyaogu nbgLtyaogu, RedirectAttributes redirectAttributes) {
		nbgLtyaoguService.delete(nbgLtyaogu);
		addMessage(redirectAttributes, "删除妖股成功");
		return "redirect:"+Global.getAdminPath()+"/nbg/nbgLtyaogu/?repage";
	}

}